﻿namespace SenenFernandez.SmartImageComparer
{
    using SenenFernandez.SmartExtensionMethods;
    using System;
    using System.Configuration;
    using System.Windows;
    using System.Windows.Interop;
    using System.Windows.Threading;

    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            if (SenenFernandez.SmartImageComparer.Properties.Resources.ApplicationTitle.JustOneApplication())
            {
                ConfigurationManager.AppSettings["culture"].GetValueOrDefault("es-MX").SetCulture();
                var mainView = new MainView();
                mainView.Show();
                var target = PresentationSource.FromVisual(mainView).CompositionTarget as HwndTarget;
                if (target != null)
                {
                    target.RenderMode = RenderMode.SoftwareOnly;
                }
            }
        }

        private void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            try
            {
                e.Exception.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                e.Handled = true;
            }
        }
    }
}